package com.sm.app;

import com.sm.config.ChatModelClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;

import java.util.List;



@Component
@Slf4j
public class SmApp {

    @Autowired
    private ChatModelClient chatModelClient;

    /**
     * 执行聊天操作，发送消息并获取回复。
     * AI基础对话(支持多轮对话记忆)
     *
     * @param message
     * @param chatId
     * @return
     */
    public String doChat(String message, String chatId) {
        ChatResponse chatResponse = chatModelClient.deepseekChatClient()
                .prompt()
                .user(message)
//                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId))
                .call()
                .chatResponse();

        String content = chatResponse.getResult().getOutput().getText();
        log.info("content: {}", content);
        return content;
    }


    /**
     * 执行聊天操作，发送消息并获取回复。
     * AI基础对话(支持多轮对话记忆，SSE流式传输)
     *
     * @param message
     * @param chatId
     * @return
     */
    public Flux<String> doChatByStream(String message, String chatId) {
        return chatModelClient.deepseekChatClient()
                .prompt()
                .user(message)
                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream()
                .content();
    }

    record SmReport(String title, List<String> suggestions) {

    }

}
